package com.barry.oscheckpoint;

import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import android.util.Log;

/**
 * Schedule a task that executes once every second.
 */

public class OSCheckPointActivityManager implements Runnable{
     Timer timer;
     List<Point> latLongPoints ;
     List<OsCheckPointObject> _listCheckPoints;
     
     public OSCheckPointActivityManager(List<OsCheckPointObject> listCheckPoints){
    	_listCheckPoints =listCheckPoints;
    	latLongPoints  = new java.util.ArrayList<Point>();
    	latLongPoints.add(new Point(	53.38416666826341,   -2.056016385577095));
    	latLongPoints.add(new Point(	53.38166451578315 ,  -2.054750382922066));
    	latLongPoints.add(new Point(	53.384377840644234 , -2.046961247942818));
    	latLongPoints.add(new Point(	53.373120252755484 , -2.0293874144772417));
    	latLongPoints.add(new Point(	53.37510446665016 ,  -2.0338613391140825));
    	latLongPoints.add(new Point(	53.3844840000000,    -2.058564400000000));
    	latLongPoints.add(new Point(	53.38296360562865 ,  -2.044236123583687));
    	latLongPoints.add(new Point(	53.382938008181966,  -2.051006019137276));
    	latLongPoints.add(new Point(	53.3840322852939,    -2.053774058840645));
    	latLongPoints.add(new Point(	53.37468842946035 ,  -2.0229286551693804));
    	latLongPoints.add(new Point(	53.37621814620396,   -2.026029288790596));
    	latLongPoints.add(new Point(	53.3780230132915 ,   -2.028260886690987));
    	latLongPoints.add(new Point(	53.3817925066906,    -2.024613082430733));
    	latLongPoints.add(new Point(	53.38233006430073,   -2.03117913009919));
    	latLongPoints.add(new Point(	53.379162216259076 , -2.0534629225949175));
    	latLongPoints.add(new Point(	53.37208970519727 ,  -2.0368546843747026));
    	latLongPoints.add(new Point(	53.383673928634956,  -2.032895743868721));
    	latLongPoints.add(new Point(	53.38408347885609 ,  -2.042766273043526));
    	latLongPoints.add(new Point(	53.376563764971756,  -2.027606427691353));
    	latLongPoints.add(new Point(	53.382176477104615,  -2.039215028307808));
    	latLongPoints.add(new Point(	53.38108855193859,   -2.0424980521420366));
    	latLongPoints.add(new Point(	53.38036538630206 ,  -2.0506197810391313));
    	 
     }

      public void run(){
    	System.out.format("About to schedule task.%n");
        timer = new Timer();
        timer.schedule(new RemindTask(latLongPoints, _listCheckPoints),
	               0,        //initial delay
	               1* 100);  //subsequent rate
    }

    class RemindTask extends TimerTask {
	int numWarningBeeps = 8;	
	List<Point> latLongPoints ;
	List<OsCheckPointObject> listCheckPoints;
	
		public RemindTask(List<Point> _latLongPoints, List<OsCheckPointObject> _listCheckPoints ){
			 latLongPoints  = _latLongPoints ;
			 listCheckPoints = _listCheckPoints;
		}


        public void run() {
        	Point point =(Point) latLongPoints.toArray()[8];
        	//for(Point point : latLongPoints ){
        		for(OsCheckPointObject osCheckPt : listCheckPoints ){
        		//	(-2.053926, -2.058483 , 53.384126, 53.384126)
        			Log.d("Tag-"  , osCheckPt.getLabel());
        		double distance =	LonLatOS.DistanceToCheckPoint(
        				osCheckPt.getLongt(),
        				osCheckPt.getLat(),
        				point.Longt, 
        				point.Lat);
        		if (distance != 100){
        			Log.d("Tag-" +  distance , osCheckPt.getLabel());
        			break;
        		}
        		}
        		  
        		//}
        }
    }

}


